package cn.edu.hpu.jie.services;

import java.util.List;

import cn.edu.hpu.jie.dao.CandidateDao;
import cn.edu.hpu.jie.entity.Candidate;
import cn.edu.hpu.jie.entity.CandidateSites;
import cn.edu.hpu.jie.util.DateUtil;

public class CandidateService {
	private CandidateDao dao = new CandidateDao();
	
	public Candidate getCandidateByStudentId(String studentid) {
		return dao.getCandidateByStudentId(studentid);
	}

	public int insertCandidate(Candidate c, CandidateSites cands, int loginid) {
		int lines = dao.insertCandidate(c, cands);
		if(lines != 0) {
			LogService ls = new LogService();
			lines = ls.addLog(lines, loginid, "添加了候选人", DateUtil.getNow());
		} 
		return lines;
	}

	public List<Candidate> getCandidateList() {
		return dao.getCandidateList();
	}

	public Candidate getCandidateById(int id) {
		return dao.getCandidteById(id);
	}

	public CandidateSites getCandidateSitesById(int id) {
		return dao.getCandidateSitesById(id);
	}

	public int updateCandidateById(Candidate c, int loginid) {
		int lines = dao.updateCandidateById(c);
		if(lines != 0) {
			LogService ls = new LogService();
			lines = ls.addLog(c.getId(), loginid, "修改了候选人基本信息", DateUtil.getNow());
		} 
		return lines;
	}

	public int updateCandidateSitesById(CandidateSites cands, int loginid) {
		int lines = dao.updateCandidateSitesById(cands);
		if(lines != 0) {
			LogService ls = new LogService();
			lines = ls.addLog(cands.getId(), loginid, "修改了候选人主页", DateUtil.getNow());
		} 
		return lines;
	}

	public int modifyEnableById(int id, int loginid) {
		int lines = dao.setEnableById(id);
		if(lines != 0) {
			LogService ls = new LogService();
			lines = ls.addLog(id, loginid, "修改了候选人状态", DateUtil.getNow());
		} 
		return lines;
	}
}
